# @Version        : 1.0
# @Update Time    : 2025/8/16 22:35
# @File           : passport.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
from pydantic import BaseModel, Field, field_validator


class LoginForm(BaseModel):
    username: str = Field(..., min_length=1, description="用户名")
    password: str = Field(..., min_length=1, description="密码")
    captcha: str = Field(..., description="验证码")
    remember_me: bool = Field(False, description="记住我")

    # 验证码验证
    @field_validator("captcha")
    def validate_captcha(cls, v: str):
        if not v:
            raise ValueError("验证码不能为空")
        if len(v) == 4:
            return v.lower()
        else:
            raise ValueError("验证码长度错误")
